﻿using System;
using System.Collections.Generic;
using System.Linq;
using Manager;
using UnityEngine;

namespace Studio
{
	// Token: 0x02000470 RID: 1136
	public static class AddObjectMale
	{
		// Token: 0x06001C3E RID: 7230 RVA: 0x000B63E4 File Offset: 0x000B45E4
		public static OCICharMale Add(string _path)
		{
			//ChaControl chaControl = Singleton<Character>.Instance.CreateMale(Singleton<Scene>.Instance.commonSpace, 0, null, null);
			//chaControl.human.customParam.Load(_path, false, true);
			//OICharInfo oicharInfo = new OICharInfo(chaControl.human.customParam, Studio.GetNewIndex());
			//CharaInfo charaInfo = new CharaInfo();
			//charaInfo.Load(_path);
			//oicharInfo.fileStatus.name = charaInfo.name;
			//return AddObjectMale.Add(chaControl, oicharInfo, null, null, true, Studio.optionSystem.initialPosition);
			return null;
		}

		// Token: 0x06001C3F RID: 7231 RVA: 0x000B6464 File Offset: 0x000B4664
		public static OCICharMale Load(OICharInfo _info, ObjectCtrlInfo _parent, TreeNodeObject _parentNode)
		{
			//ChaControl chaControl = Singleton<Character>.Instance.CreateMale(Singleton<Scene>.Instance.commonSpace, -1, _info.charFile, _info.fileStatus);
			//_info.charFile = chaControl.human.customParam;
			//OCICharMale ocicharMale = AddObjectMale.Add(chaControl, _info, _parent, _parentNode, false, -1);
			//using (Dictionary<int, List<ObjectInfo>>.Enumerator enumerator = _info.child.GetEnumerator())
			//{
			//	while (enumerator.MoveNext())
			//	{
			//		KeyValuePair<int, List<ObjectInfo>> v = enumerator.Current;
			//		AddObjectAssist.LoadChild(v.Value, ocicharMale, ocicharMale.dicAccessoryPoint.First((KeyValuePair<TreeNodeObject, int> x) => x.Value == v.Key).Key);
			//	}
			//}
			//return ocicharMale;
			return null;
		}

		// Token: 0x06001C40 RID: 7232 RVA: 0x000B6538 File Offset: 0x000B4738
		private static OCICharMale Add(ChaControl _male, OICharInfo _info, ObjectCtrlInfo _parent, TreeNodeObject _parentNode, bool _addInfo, int _initialPosition)
		{
			OCICharMale ocicharMale = new OCICharMale();
			_male.Load(_info.charFile);
			_male.InitializeExpression(true);
			ocicharMale.charInfo = _male;
			ocicharMale.fullBodyIK = _male.human.ik.FBIK;
			ocicharMale.objectInfo = _info;
			string name = (!_addInfo) ? string.Empty : _info.fileStatus.name;
			_info.fileStatus = ocicharMale.charStatus;
			if (_addInfo)
			{
				_info.fileStatus.name = name;
			}
			GuideObject guideObject = Singleton<GuideObjectManager>.Instance.Add(_male.transform, _info.dicKey);
			guideObject.scaleSelect = 0.1f;
			guideObject.scaleRot = 0.05f;
			GuideObject guideObject2 = guideObject;
			guideObject2.isActiveFunc = (GuideObject.IsActiveFunc)Delegate.Combine(guideObject2.isActiveFunc, new GuideObject.IsActiveFunc(ocicharMale.OnSelect));
			ocicharMale.guideObject = guideObject;
			ocicharMale.optionItemCtrl = _male.gameObject.AddComponent<OptionItemCtrl>();
			ocicharMale.optionItemCtrl.animator = _male.animBody;
			ocicharMale.optionItemCtrl.oiCharInfo = _info;
			ChangeAmount changeAmount = _info.changeAmount;
			changeAmount.onChangeScale = (Action<Vector3>)Delegate.Combine(changeAmount.onChangeScale, new Action<Vector3>(ocicharMale.optionItemCtrl.ChangeScale));
			ocicharMale.charAnimeCtrl = _male.gameObject.AddComponent<CharAnimeCtrl>();
			ocicharMale.charAnimeCtrl.animator = _male.animBody;
			ocicharMale.charAnimeCtrl.oiCharInfo = _info;
			AddObjectAssist.InitHandAnime(ocicharMale);
			int group = _info.animeInfo.group;
			int category = _info.animeInfo.category;
			int no = _info.animeInfo.no;
			float animeNormalizedTime = _info.animeNormalizedTime;
			ocicharMale.LoadAnime(0, 0, 1, 0f);
			_male.animBody.Update(0f);
			_info.animeInfo.group = group;
			_info.animeInfo.category = category;
			_info.animeInfo.no = no;
			_info.animeNormalizedTime = animeNormalizedTime;
			if (_addInfo)
			{
				Studio.AddInfo(_info, ocicharMale);
			}
			else
			{
				Studio.AddObjectCtrlInfo(ocicharMale);
			}
			TreeNodeObject treeNodeObject = Studio.AddNode(_male.fileStatus.name, null);
			treeNodeObject.enableChangeParent = false;
			treeNodeObject.treeState = _info.treeState;
			TreeNodeObject treeNodeObject2 = treeNodeObject;
			treeNodeObject2.onVisible = (TreeNodeObject.OnVisibleFunc)Delegate.Combine(treeNodeObject2.onVisible, new TreeNodeObject.OnVisibleFunc(ocicharMale.OnVisible));
			treeNodeObject.enableVisible = true;
			treeNodeObject.visible = _info.visible;
			guideObject.guideSelect.treeNodeObject = treeNodeObject;
			ocicharMale.treeNodeObject = treeNodeObject;
			AddObjectAssist.InitBone(ocicharMale, _male.objBodyBone.transform, Singleton<Info>.Instance.dicMaleBoneInfo);
			AddObjectAssist.InitIKTarget(ocicharMale, _addInfo);
			AddObjectAssist.InitLookAt(ocicharMale);
			AddObjectAssist.InitAccessoryPoint(ocicharMale);
			ocicharMale.voiceCtrl.ociChar = ocicharMale;
			List<DynamicBone> list = new List<DynamicBone>();
			foreach (GameObject gameObject in from v in _male.objHairs
			where v != null
			select v)
			{
				list.AddRange(gameObject.GetComponents<DynamicBone>());
			}
			ocicharMale.InitKinematic(_male.gameObject, ocicharMale.fullBodyIK, _male.neckLookCtrl, (from v in list
			where v != null
			select v).ToArray<DynamicBone>(), null);
			if (_initialPosition == 1)
			{
				_info.changeAmount.pos = Singleton<Studio>.Instance.cameraCtrl.targetPos;
			}
			_info.changeAmount.OnChange();
			treeNodeObject.treeState = TreeNodeObject.TreeState.Close;
			Studio.AddCtrlInfo(ocicharMale);
			if (_parent != null)
			{
				_parent.OnLoadAttach((!(_parentNode != null)) ? _parent.treeNodeObject : _parentNode, ocicharMale);
			}
			ocicharMale.LoadAnime(_info.animeInfo.group, _info.animeInfo.category, _info.animeInfo.no, _info.animeNormalizedTime);
			ocicharMale.ActiveKinematicMode(OICharInfo.KinematicMode.IK, _info.enableIK, true);
			for (int k = 0; k < 5; k++)
			{
				ocicharMale.ActiveIK((OIBoneInfo.BoneGroup)(1 << k), _info.activeIK[k], false);
			}
			foreach (var callback in FKCtrl.parts.Select((OIBoneInfo.BoneGroup p, int i) => new
			{
				p,
				i
			}))
			{
				ocicharMale.ActiveFK(callback.p, ocicharMale.oiCharInfo.activeFK[callback.i], ocicharMale.oiCharInfo.activeFK[callback.i]);
			}
			ocicharMale.ActiveKinematicMode(OICharInfo.KinematicMode.FK, _info.enableFK, true);
			for (int j = 0; j < _info.expression.Length; j++)
			{
				ocicharMale.charInfo.EnableExpressionCategory(j, _info.expression[j]);
			}
			ocicharMale.animeSpeed = ocicharMale.animeSpeed;
			ocicharMale.SetVisibleSon(_info.visibleSon);
			ocicharMale.SetVisibleSimple(_info.visibleSimple);
			ocicharMale.SetSimpleColor(_info.simpleColor);
			AddObjectAssist.UpdateState(ocicharMale);
			return ocicharMale;
		}
	}
}
